cmake_minimum_required(VERSION 3.10)
project(PAL4_PackUnPack)

# 禁用ALL_BUILD和ZERO_CHECK项目
set(CMAKE_SUPPRESS_REGENERATION TRUE)
set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1)

# 设置C++标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 添加调试信息
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")

# 添加安全性忽略和警告禁用
if(MSVC)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS)
    # 禁用特定警告
    # 4244: 精度损失转换
    # 4267: size_t到较小类型转换
    # 4311, 4302: 指针截断
    # 4312: 类型强制转换
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4244 /wd4267 /wd4311 /wd4302 /wd4312")
endif()

# 添加Windows平台定义
if(WIN32)
    add_definitions(-D_WIN32)
    if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        add_definitions(-D_WIN64 -D_AMD64_ -DWIN32)
    else()
        add_definitions(-D_X86_ -DWIN32)
    endif()
endif()

# 添加可执行文件
add_executable(PAL4_PackUnPack
    main.cpp
    minilzo/minilzo.c
    EncDec.c
    ProgressBar.cpp
)

# 包含头文件目录
target_include_directories(PAL4_PackUnPack PRIVATE 
    ${CMAKE_CURRENT_SOURCE_DIR}
    ${CMAKE_CURRENT_SOURCE_DIR}/minilzo
)

# 设置输出目录
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) 

# 添加安装目标
install(TARGETS PAL4_PackUnPack
    RUNTIME DESTINATION "G:/PAL4/Tools/PackTool"
)

# 添加自定义命令在构建后拷贝可执行文件
add_custom_command(
    TARGET PAL4_PackUnPack
    POST_BUILD
    COMMAND ${CMAKE_COMMAND} -E copy 
            $<TARGET_FILE:PAL4_PackUnPack> 
            "G:/PAL4/Tools/PackTool/PAL4_PackUnPack.exe"
    COMMENT "正在拷贝可执行文件到G:/PAL4/Tools/PackTool..."
) 